//
//  OrderLookViewController.m
//  mcosApp
//
//  Created by YaSha_Tom on 2018/12/13.
//  Copyright © 2018年 YaSha-Tom. All rights reserved.
//

#import "OrderLookViewController.h"
#import "OrderLookModel.h"
#import "DataManager.h"

@interface OrderLookViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,copy)NSArray *titleArray;
@property (nonatomic,strong)NSArray *dataSource;
@property (nonatomic,strong) NSMutableArray *contentArray;

@end

@implementation OrderLookViewController
- (NSMutableArray *)contentArray{
    if (!_contentArray) {
        _contentArray = [NSMutableArray array];
    }
    return _contentArray;
}
- (NSArray *)titleArray {
    if (!_titleArray) {
        _titleArray = @[@"姓名",@"手机",@"地址信息",@"楼盘",@"房号",@"定金金额(元)",@"意向等级",@"设计师",@"营销人员",@"门店",@"房屋户型",@"装修系列",@"房产证面积(m²)",@"装修预算",@"计划装修时间",@"房屋类型",@"是否已交房",@"预计交房时间",@"是否首次装修",@"是否贷款",@"备注"];
    }
    return _titleArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"订单查看";
    self.view.backgroundColor = [UIColor whiteColor];
    [self initUI];
    [self doNetworking];
}
- (void)initUI {
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, kSCREEN_HEIGHT-kTopHeight) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
}- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.titleArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.01;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;//取消cell 的点击效果
    cell.textLabel.text = self.titleArray[indexPath.row];
    if (self.contentArray.count > 0) {
        cell.detailTextLabel.text = self.contentArray[indexPath.row];
    }
    return cell;
}
- (void)doNetworking{
    NSString *urlString = [NSString stringWithFormat:@"%@%@",Domain,getOrderInfo];
    NSDictionary *dic = @{@"id":self.id};
    [YSNetManager ys_request_GETWithUrlString:urlString isNeedCache:NO parameters:dic successBlock:^(id response) {
        NSLog(@"成功%@",response);
        if ([response[@"code"]  isEqual: @1]) {
            self.dataSource = [DataManager getOrderLookData:response];
            [self dataProcessing];
        }else{
            [QMUITips showSucceed:response[@"msg"] inView:self.view hideAfterDelay:1];
        }
    } failureBlock:^(NSError *error) {
        NSLog(@"失败%@",error);
    } progress:nil];
}
- (void)dataProcessing {
    OrderLookModel *model = self.dataSource[0];
    [self.contentArray addObject:model.name];
    [self.contentArray addObject:model.mobile];
    [self.contentArray addObject:[NSString stringWithFormat:@"%@%@%@",model.province,model.city,model.area]];
    [self.contentArray addObject:[NSString stringWithFormat:@"%@%@",model.buildName,model.buildGroupName]];
    [self.contentArray addObject:model.address];
    [self.contentArray addObject:model.bookMoney];
    [self.contentArray addObject:model.yxGrade];
    
    [self.contentArray addObject:model.dsgName];
    [self.contentArray addObject:model.saleName];
    [self.contentArray addObject:model.franShopName];
    [self.contentArray addObject:[NSString stringWithFormat:@"%@室 %@厅 %@厨房 %@卫 %@阳台",model.hxShi,model.hxTing,model.hxChu,model.hxWei,model.hxYangtai]];
    [self.contentArray addObject:model.styleLike];
    [self.contentArray addObject:[NSString stringWithFormat:@"%@",model.size]];
    [self.contentArray addObject:model.budget];
    [self.contentArray addObject:model.planzxDateStr];
    [self.contentArray addObject:model.type];
    if ([model.havehome integerValue] == 0) {
        [self.contentArray addObject:@"否"];
    }else{
        [self.contentArray addObject:@"是"];
    }
    [self.contentArray addObject:model.planCompleteDate?model.planCompleteDate:@""];
    if ([model.firstZxFlag integerValue] == 0) {
        [self.contentArray addObject:@"否"];
    }else{
        [self.contentArray addObject:@"是"];
    }
    if ([model.loanFlag integerValue] == 0) {
        [self.contentArray addObject:@"否"];
    }else{
        [self.contentArray addObject:@"是"];
    }
    [self.contentArray addObject:model.remark];
    [self.tableView reloadData];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
